

  Ext.ns('Ext.grid');
  Ext.grid.normalGrid = Ext.extend(Ext.grid.EditorGridPanel,{
    me:null,
    initComponent:function(){
    	me = this;
    	/**
    	 * for columns
    	 */
    	var nc = me.normalColumns ;
    	if(nc){
    		me.cm = me.buildCM(nc);
            me.store = me.buildStore(nc);
       }
       /**
        * callback
        */
        if(me.callback){
        	me.store.on('add',function(store){
        		  var cm = Ext.getCmp(store.gridId).getColumnModel();
                   me.callback(cm);
            	
            });
        }
       
       /**
         * defautls params
         */
        me.stripeRows=true;
      	me.enableColumnMove=false;
      	me.enableHdMenu=false;
      	me.sm=new Ext.grid.RowSelectionModel();
        Ext.grid.normalGrid.superclass.initComponent.call(me);
      
    },
     /**
     * build column model
     */
    buildCM:function(cms){
    	var widthPerColumn = 100;
    	if(me.isForceFit){
    		widthPerColumn = (me.width - 25)/(cms.length==0?1:cms.length) ;
    	}
    	var temp,cmArray = [];
    	for(var i=0,len = cms.length;i<len;i++){
    	             temp = {};
    	        	 temp['header'] = cms[i];
    	        	 temp['id'] = i;
    	        	 temp['dataIndex'] = cms[i];
    	        	 temp['width'] = widthPerColumn;
    	        	 cmArray.push(temp);
    	   }
    	 return  new Ext.grid.ColumnModel({
    		  columns:cmArray,
    		  defaults:{
      	            sortable:false,
      	            menuDisabled:true
      	            }
    	    });
    	   
    },
    /**
     * build store
     */
    buildStore:function(cms){
     var temp,indexArray = [];
     for(var i=0,len = cms.length;i<len;i++){
    	             temp = {};
    	        	 temp['name'] = cms[i];
    	        	 indexArray.push(temp);
    	   }
    	  
     return new Ext.data.Store({
     	         gridId:me.id||Ext.id('','grid_'),
            	 autoLoad:true,
            	 data:[],
            	 reader:new Ext.data.ArrayReader({},indexArray)
  		    });
    },
		 /**
		  * add a new Record
		  */
   		 addRecord:function(record){
   		     var r  = new Ext.data.Record(record);
   		      me.store.add(r);
   		   },
   		   /**
   		    * get all records
   		    *  if pattern is true   return the object format of the all records
   		    *  if pattern is false  return the String format of the all records
   		    * 
   		    */
   		 getRecords:function(pattern,exceptColumn){
   		      
   		 	 var records = [];
   		 	me.store.each(function(r){
   		 		if(pattern){
   		 			  if(exceptColumn){
   		 			  	 var temp = {};
   		 			     for(var p in r.data){
   		 			          if(exceptColumn.indexOf(p)> -1){
   		 			           continue;
   		 			          }
   		 			         temp[p] = r.data[p]; 
   		 			     }
   		 			     records.push(temp);
   		 			  }else{
   		 			  	  records.push(r.data);
   		 			  }
   		 		}
   		 		else{
   		 			 if(exceptColumn){
   		 			  	 var temp = {};
   		 			     for(var p in r.data){
   		 			          if(exceptColumn.indexOf(p)> -1){
   		 			           continue;
   		 			          }
   		 			         temp[p] = r.data[p]; 
   		 			     }
   		 			     records.push(Ext.encode(temp));
   		 			  }else{
   		 			  	  records.push(Ext.encode(r.data));
   		 			  }
   		 			
   		 		    
   		 		}
   		 	});
   		    	if(pattern){
   		 		    return records ;
   		 		}else{
   		 		  return '['+ records +']';
   		 		}
   		 },
   		 doDelete:function(id){
   		  alert(id);
   		 
   		 
   		 
   		 
   		 
   		 }
   		
    
    
    
  });